﻿using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Linq;
using ComputerVision.Data;
using ComputerVision.Data.Repositories;

namespace ComputerVision.Services.RoleService
{
    public class MembershipService : IService<aspnet_Membership>
    {
        private readonly IEntityRepository<aspnet_Membership> _memberShipRepository;

        public MembershipService(IEntityRepository<aspnet_Membership> memberShipRepository)
        {
            _memberShipRepository = memberShipRepository;
        }

        public aspnet_Membership Create(aspnet_Membership t)
        {
            throw new NotImplementedException();
        }

        public aspnet_Membership Update(aspnet_Membership item)
        {
            aspnet_Membership itemDetails;
            //try
            //{
            //    itemDetails = _memberShipRepository.Get(item.RoleId);
            //    itemDetails.RoleName = item.RoleName;
            //    itemDetails.LoweredRoleName = item.LoweredRoleName.ToLower();
            //    _memberShipRepository.CommitChanges();
            //}
            //catch (DbEntityValidationException dbEx)
            //{
            //    string msg = string.Empty;
            //    foreach (DbEntityValidationResult validationErrors in dbEx.EntityValidationErrors)
            //        foreach (DbValidationError validationError in validationErrors.ValidationErrors)
            //            msg += Environment.NewLine +
            //                   string.Format("Property: {0} Error: {1}", validationError.PropertyName,
            //                       validationError.ErrorMessage);

            //    var fail = new Exception(msg, dbEx);
            //    throw fail;
            //}
            return null;
        }

        public aspnet_Membership Detail(Guid id)
        {
            aspnet_Membership item = _memberShipRepository.Get(id);
            return item;
        }

        public aspnet_Membership Detail(int id)
        {
            aspnet_Membership item = _memberShipRepository.Get(id);
            return item;
        }

        public aspnet_Membership Detail(string id)
        {
            aspnet_Membership item = _memberShipRepository.Get(id);
            return item;
        }
        
        public List<aspnet_Membership> ToList()
        {
            var item = _memberShipRepository.GetAll().ToList();
            return item;
        }

        public void Delete(aspnet_Membership t)
        {
            throw new NotImplementedException();
        }
    }
}